#coding=utf-8
import json
import datetime
import pytz
import time

def GenerateURL(url,params):
    url = url + "?"
    for k,v in params.items():
        url = url + "&" + k + "=" + str(v)
    return url


def ParseJson(text):
    #---Parse Json---
    # var SSsrijYp = { XXXXX};
    #需要取等号后面的内容，移除分号
    text = text
    pos = text.find("=")
    len = text.__len__()
    text = text[pos+1:len]

    # 如果最后一位是分号，移除
    if text[text.__len__()-1] == ";":
        text = text[0:text.__len__()-1]
    j = json.loads(text, encoding='utf-8')
    return j


def ProcessEastMoneyAuthor(author):
    authors = author.split(",")
    authors2 = []
    for name in authors:
        name = name.replace(" ","")#去除空格
        name = name.replace("\r\n","")#去除回车
        authors2.append(name)
    return authors2


# 2016年03月10日 00:00
def ProcessEastMoneyDateTime(strDateTime):
    year = strDateTime[0:4]
    month = strDateTime[5:7]
    day = strDateTime[8:10]
    hour = strDateTime[12:14]
    min = strDateTime[15:17]
    return datetime.datetime(int(year),int(month),int(day),int(hour),int(min))


#2016-09-13T07:24:21
def ProcessEastMoneyDateTime2(strDateTime):
    year = strDateTime[0:4]
    month = strDateTime[5:7]
    day = strDateTime[8:10]
    hour = strDateTime[11:13]
    min = strDateTime[14:16]
    sec = strDateTime[17:19]
    return datetime.datetime(int(year),int(month),int(day),int(hour),int(min),int(sec))


#2016/8/30 8:16:01 -format- "%Y/%m/%d %H:%M:%S"
#2016-11-15 -format- "%Y-%m-%d"
def StringToDateTime(strDateTime, format):
    return datetime.datetime.strptime(strDateTime, format)
